def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True


def x(s):
    words = s.split()
    numbers = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8,
               'nine': 9}

    if len(words) != 3:
        print("Wrong input")
        return

    number = ""
    for word in words:
        if word in numbers:
            number += str(numbers[word])
        else:
            print("Wrong input")
            return

    num = int(number)

    if 100 <= num <= 999 and is_prime(num):
        print(num)
        return

    lower = num - 1
    upper = num + 1
    while True:
        if lower >= 100 and is_prime(lower):
            print(lower)
            return
        elif upper <= 999 and is_prime(upper):
            print(upper)
            return
        lower -= 1
        upper += 1

    print("Wrong input")


input_str = input()
x(input_str)
